package com.xyebank.ledger.service.sjsh.adaper;

import java.util.Date;

import com.xyebank.ledger.util.DateConverter;
import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LPaymentInf;
import com.xyebank.ledger.service.common.conveter.PayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.vo.deal.SJSHCashCreditVo;

@Component(value = "sjshCreditBeanConverter")
public class SJSHCreditBeanConverter implements PayBeanConverter<SJSHCashCreditVo> {

	ModelMapper modelMapper = new ModelMapper();


	// 不能采取注入方式
	private DateConverter dateConverter = new DateConverter();

	class NXApplyPropertyMap extends PropertyMap<SJSHCashCreditVo, LPaymentInf> {
		// 注意 不要有重复的映射，不然会报错
		protected void configure() {
			// 提现订单号
			map(source.getContactNo(), destination.getOrgOrderNo());
			// 申请人电话
			map(source.getMblNo(), destination.getMblNo());
			// 申请提现时间
			using(dateConverter).map(source.getApplTime(), destination.getApplyTime());
			// 累计提现额(随借随还)
			map(source.getLtdLendAmt(), destination.getLtdLendAmt());
			// 当天提现额(随借随还)
			map(source.getTotalAmount(), destination.getTotalAmount());
			// 当天提现次数(随借随还)
			map(source.getTotalNum(), destination.getTotalNum());
			// 放款金额
			map(source.getTotalAmount(), destination.getLoanAmount());
			// 放款时间
			map(source.getMsdPushDate(), destination.getLoanTime());
		}
	}

	public SJSHCreditBeanConverter() {
		modelMapper.addMappings(new NXApplyPropertyMap());
	}

	@Override
	public LPaymentInf covert(SJSHCashCreditVo x) {
		LPaymentInf entity = modelMapper.map(x, LPaymentInf.class);
		entity.setDataSource(x.getChannelNo().equals("51000005") ? CommonConstant.JRY_STR : CommonConstant.SJD_STR);
		entity.setOrgNo(ProductConstant.SJSH_LOAN_ORG);
		entity.setProductNo(ProductConstant.SJSH_LOAN_PROD_ID);
		entity.setId(IDUtil.generateId(x.getId().toString(), "sjsh_credit"));
		return entity;
	}
}
